package com.liangzhong.modules.login.command
{
	import com.common.utils.Debug;
	import com.liangzhong.constants.ApplicationConstants;
	import com.liangzhong.model.AppData;
	import com.liangzhong.modules.login.mediator.LoginMediator;
	import com.liangzhong.proxy.login.LoginProxy;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	/**
	 *登录控制 
	 * @author lxh
	 * 
	 */	
	public class LoginCommand extends SimpleCommand
	{
		public function LoginCommand()
		{
			super();
		}
		override public function execute(notification:INotification):void
		{
			var loginProxy :LoginProxy = facade.retrieveProxy(LoginProxy.ProxyName) as LoginProxy;
			var userId :Number;
			var userKey :String;
			switch(notification.getName())
			{
				case ApplicationConstants.Login_TGW://TGW Request
				{
					loginProxy.TGWRequest();
					Debug.echo("Login --> TGWRequest");
					break;
				}
				case ApplicationConstants.Login_login://登陆请求
				{
					userId = notification.getBody().userId;
					userKey = notification.getBody().userKey;
					AppData.getInstance().user.userID = userId;
					loginProxy.login(userId,userKey);
					Debug.echo("Login --> user login req userId = " + userId,Debug.TRACER);
					var info :String = "Login Request userId = " + userId + ";Key = " + userKey + " Server IP:" + AppData.getInstance().ip + " Server Port:" + AppData.getInstance().port;
					Debug.log(info,7);
					break;
				}
				case LoginProxy.Login_Result://登录返回
				{
					var retCode :int = int(notification.getBody());
					Debug.echo("Login --> user login res code = " + retCode,Debug.TRACER);
					if(retCode == 0)//login success
					{
						this.sendNotification(LoginMediator.Login_Login_Success);
						if(AppData.getInstance().user.isGuideing == false)
						{
							//获取用户相关信息
							this.sendNotification(ApplicationConstants.Main_Get_User_Base_Info);
						}
					}
					else
					{
						this.sendNotification(LoginMediator.Login_Login_Failed);
					}
					break;
				} 
				case ApplicationConstants.Login_Get_Login_Award_Info://
				{
					//loginProxy.getLoginAwardInfo();
					//loginProxy.getSignInfo();
					break;
				}
				case LoginProxy.Login_LoginAwardInfo_Result://获取登录奖励信息 res 
				{
					this.sendNotification(LoginMediator.Login_AwardInfo_Result,notification.getBody());
					break;
				}
				case ApplicationConstants.Login_Get_Login_Award://获取登录奖励
				{
					loginProxy.getLoginAward();
					break;
				}
				case LoginProxy.Login_GetLoginAward_Result://获取登录奖励 res 
				{
					this.sendNotification(LoginMediator.Login_GetAward_Result,notification.getBody());
					break;
				}
				case ApplicationConstants.Login_Get_SignInfo://获取签到信息
				{
					loginProxy.getSignInfo();
					break;
				}
				case ApplicationConstants.Login_User_Sign://签到
				{
					loginProxy.userSign();
					break;
				}
				case ApplicationConstants.Login_User_Resign://补签
				{
					loginProxy.userReSign();
					break;
				}
				case ApplicationConstants.Login_User_Get_Sign_Award://获取签到奖励
				{
					loginProxy.userGetSignAward(int(notification.getBody()));
					break;
				}
				case ApplicationConstants.Login_User_Get_Qzone_Vip_Award://获取黄钻礼包
				{
					loginProxy.getQzoneVipAward();
					break;
				}
				case ApplicationConstants.GUIDE_SETTING://新手设置
				{
					loginProxy.guideSetting(AppData.getInstance().guideManager.guideSettingVo);
					break;
				}
				case ApplicationConstants.GUIDE_CHECK_NAME://名字验证
				{
					loginProxy.guideCheckName(String(notification.getBody()));
					break;
				}
			}
		}
	}
}